<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.List,org.apache.lucene.document.Document"%>


<%@page import="component.fulltextsearch.util.Page"%>
<%@page import="component.fulltextsearch.util.SearchConfigUtil"%>
<%@page import="component.fulltextsearch.constant.SearchConstant"%><html>
<head>
<%
	String context = request.getContextPath();

	Page curPage = (Page)request.getAttribute("page");
	List curPageData = curPage.getData();
	long totalCount = curPage.getTotalCount();
	long curStartNo = curPage.getStart() + 1;	
	long curEndNo = curPage.getStart() + curPageData.size();
	long curPageNo = curPage.getCurrentPageNo();
	long pageSize = curPage.getPageSize();
	
	String queryExpression = (String)request.getAttribute("queryExpression");
	if(queryExpression == null) queryExpression = "";
	
	//高级搜索的值
	String advanceQueryExpression = (String)request.getAttribute("advanceQueryExpression");
	String advanceQueryExpression2 = (String)request.getAttribute("advanceQueryExpression2");;//用于高级搜索页面显示的值
	String date = (String)request.getAttribute("date");
	String position = (String)request.getAttribute("position");
	if(advanceQueryExpression == null) advanceQueryExpression = "";
	if(advanceQueryExpression2 == null) advanceQueryExpression2 = "";
	if(date == null) date = "";
	if(position == null) position = "";
	
	String  action = context + SearchConfigUtil.getSearchUrl() + "?action=doSearch";
	
	String url = SearchConfigUtil.getBusUrl() + "?" + SearchConstant.NAME_BUSINESSSTRING + "=";
%>

<title></title>

<link href="<%=(context + SearchConfigUtil.getSimpleCss())%>" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=(context + SearchConfigUtil.getSearchPath())%>/js/SearchUtil.js"></script>

<script type="text/javascript">
	var searchUtil = new SearchUtil("<%=context%>","<%=SearchConfigUtil.getSearchUrl()%>");
	
	window.onload = function(){
		var obj = document.getElementById("advanceSearch");
		var url = "<%=(context + SearchConfigUtil.getSearchPath())%>/advanceSearch.jsp?advanceQueryExpression=" + getAdvanceQueryExpression() + "&date=<%=date%>&position=<%=position%>&pageSize=<%=pageSize%>";
		//url = url.replace("+","%20");// %2b
		obj.href = encodeURI(url);
	}
	
	function getAdvanceQueryExpression(){
		return "<%=advanceQueryExpression2%>";
		/*
		var advanceQueryExpression = "<%=advanceQueryExpression%>";
		if(advanceQueryExpression == ""){
			return "<%=queryExpression%>,,";
		}
		
		var noFieldAnd = "";
		var noFieldOr = "";
		var noFieldNot = "";
		
		var arr1 = advanceQueryExpression.split("-");
		if(advanceQueryExpression.indexOf("-")!=-1){
			noFieldNot = arr1[1];
		}
		
		if(arr1[0].indexOf("+")!=-1){
			var temp = arr1[0];
			if(temp.indexOf("(")==-1){
				noFieldAnd = temp.substring(1);
			}else{
				var tempArr = temp.split("(");
				noFieldAnd = tempArr[0].substring(1);
				var index = noFieldAnd.indexOf("+");
				noFieldAnd = noFieldAnd.substring(0,index);
				
				index = tempArr[1].indexOf(")");
				noFieldOr = tempArr[1].substring(0,index);
				
			}
		}
		
		//alert(noFieldAnd + "," + noFieldOr + "," + noFieldNot);
		return noFieldAnd + "," + noFieldOr + "," + noFieldNot;
		*/
	}
</script>

</head>
<body>
<DIV class="gbh" style="LEFT: 0px"></DIV>

<FORM action="<%=action%>" method="post">
	
	<!-- 高级搜索的隐藏域 -->
	<input type="hidden" name="advanceQueryExpression" id="advanceQueryExpression" value="<%=advanceQueryExpression%>" />
	<input type="hidden" name="date" value="<%=date%>" />
	<input type="hidden" name="position" value="<%=position%>" >
	
	<TABLE class="ts" id="sft" style="CLEAR: both">
		<TBODY>
			<TR vAlign="top">
				<TD id="sff" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 7px; WIDTH: 100%; PADDING-TOP: 1px">
					<TABLE class="ts" style="MARGIN-TOP: 25px">
						<TBODY>
							<TR>
								<TD noWrap><IMG	src="<%=(context + SearchConfigUtil.getSearchPath())%>/image/logo.jpg" /></TD>
								<TD noWrap>
									<INPUT type="hidden" name="action" value="doSearch" />
									<INPUT type="hidden" name="pageSize" value="<%=pageSize %>" />
									<INPUT type="hidden" id="pageNo" name="pageNo" value="<%=curPageNo %>" />
									<INPUT type="hidden" id="queryExpression" name="queryExpression" value="<%=queryExpression %>" />
									<INPUT type="text" onkeydown="if(event.keyCode==13){doSearch('query1');}" title="Gever 搜索" maxLength="2048" size="41" id="query1" name="query1" value="<%=queryExpression %>"  />
									<INPUT type="button" name="btnG" onclick="searchUtil.doSearch('query1')" value="搜索" />
								</TD>
								<TD class="nobr" style="PADDING-RIGHT: 6px; PADDING-LEFT: 6px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px">
									<A id="advanceSearch" href="" >高级搜索</A>
								</TD>
							</TR>
						</TBODY>
					</TABLE>
				</TD>
			</TR>
		</TBODY>
	</TABLE>
	
	
	<DIV id="ssb">
		<DIV id="prs"><B>结果</B></DIV><P>&nbsp;约有 <B><%=totalCount %></B> 项查询结果<%if (curEndNo == 0) {%><%} else {%>，以下是第<B><%=curStartNo %></B>-<B><%=curEndNo %></B>项<%}%> &nbsp;</P>
	</DIV>
	
	<DIV class="med" id="res">
		<% for(int i =0; i < curPageData.size(); i ++) {
			Document document = (Document)curPageData.get(i);
			String name = document.getField(SearchConstant.NAME_NAME).stringValue();
			String summary = document.getField(SearchConstant.NAME_SUMMARY).stringValue();
			String pageContent = document.getField(SearchConstant.PAGE_CONTENT).stringValue();
			String businessString = document.getField(SearchConstant.NAME_BUSINESSSTRING).stringValue();
		%> 
		<DIV>
			<OL>
				<LI class="g">
				<H3 class="r">
					<A class="l" href="<%=url + businessString%>" target="_blank">
					<%=name%>
					</A>
				</H3>
				<DIV class="s" style="width:50%"><%=pageContent%><B>....</B><BR/></DIV>
				</LI>
			</OL>
		</DIV>
		<%} %>
	</DIV>
	
	<DIV class="med" id="res">
	<DIV class="e">
	<TABLE id="nav"	style="MARGIN: auto auto 1.4em; DIRECTION: ltr; BORDER-COLLAPSE: collapse; TEXT-ALIGN: center"	align="center">
		<TBODY>
			<TR vAlign="top">
			<%			
				long linkSize = 10;
				long halfLinkSize = linkSize/2;			
				long startPageNO = (curPageNo > halfLinkSize) ? (curPageNo - halfLinkSize) : 1;
				long totalPageCount = curPage.getTotalPageCount();
				long endPageNO = (startPageNO + linkSize) < totalPageCount ? (startPageNO + linkSize) : totalPageCount;
				if (endPageNO == totalPageCount) {
					startPageNO =  (totalPageCount >  linkSize) ? totalPageCount -  linkSize : 1;
				}
				if (curPageNo > 1) {
					long toPage = curPageNo - 1;
					%>
					<TD class="b"><A onclick="searchUtil.toPage(<%=toPage %>)"  href="#">
						<SPAN class="csb ch" style="BACKGROUND-POSITION: -76px 0px; WIDTH: 66px; MARGIN-RIGHT: 34px"></SPAN><B>上一页</B>
					</A></TD>
					<%
				} else {
					%>
					<TD class="b"><SPAN class="csb"	style="BACKGROUND-POSITION: -26px 0px; WIDTH: 18px"></SPAN></TD>
					<%
				}
				for (long i = startPageNO; i <= endPageNO; i ++) {
					if (curPageNo != i) {					
						%>
						<TD><A href="#"	onclick="searchUtil.toPage(<%=i %>)">
							<SPAN class="csb ch" style="BACKGROUND-POSITION: -60px 0px; WIDTH: 16px"></SPAN><%=i %>
						</A></TD>
						<%
					} else {
						%>
						<TD class="cur"><SPAN class="csb" style="BACKGROUND-POSITION: -44px 0px; WIDTH: 16px"></SPAN><%=i %></TD>
						<%
					}
				}
				if (curPageNo < totalPageCount) {
					long toPage = curPageNo + 1;
					%>
					<TD class="b"><A onclick="searchUtil.toPage(<%=toPage %>)" href="#">
						<SPAN class="csb ch" style="BACKGROUND-POSITION: -76px 0px; WIDTH: 66px; MARGIN-RIGHT: 34px"></SPAN><B>下一页</B>
					</A></TD>
					<%
				} else {
					%>
					<TD class="b"><SPAN class="csb"	style="BACKGROUND-POSITION: -26px 0px; WIDTH: 18px"></SPAN></TD>
					<%
				}
			%>
			</TR>
		</TBODY>
	</TABLE>
	</DIV>
	</DIV>
	
	<DIV class="clr" style="MARGIN-TOP: 1.4em; TEXT-ALIGN: center">
		<DIV id="bsf" style="PADDING-RIGHT: 0px; MARGIN-TOP: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 1.8em; PADDING-TOP: 1.8em">	
			<DIV>
				<INPUT type="text" onkeydown="if(event.keyCode==13){searchUtil.doSearch('query2');}" title="Gever 搜索" maxLength="2048" size="41" id="query2" name="query2" value="<%=queryExpression %>" />
				<INPUT type="button" name="btnG" onclick="searchUtil.doSearch('query2')" value="搜索" />
			</DIV>
		</DIV>
	</DIV>
</FORM>
</body>
</html>

